<?php


namespace App\Repositories\Game\Lucky;

use App\Traits\Singleton;
use App\Models\GameDB\LuckyStrike\RebateBalanceLog as Model;
class StrikeBalanceLogRepository
{
    use Singleton;

    public function swap(int $userId, int $count): Model
    {
        $balance = StrikeUserRepositories::getInstance()->userBalance($userId);
        return $this->create([
            "user_id" => $userId,
            "source"  => "strike",  //  暂无用到
            "amount"  => $count,
            "balance" => $balance + $count,
        ]);
    }

    public function draw(int $userId, int $count): Model
    {
        $balance = StrikeUserRepositories::getInstance()->userBalance($userId);
        return $this->create([
            "user_id" => $userId,
            "source"  => "strike",  //  暂无用到
            "amount"  => $count,
            "balance" => $balance - $count,
        ]);
    }

    public function create(array $data): Model
    {
        $model = new Model();
        $model->fill($data);
        $model->save();
        $model->refresh();
        return $model;
    }
}
